import request from '@/uni_modules/u-ajax/js_sdk'


const instance = request.create({
	baseURL: "http://localhost:6060/"
})

// 添加请求拦截器
instance.interceptors.request.use(
	config => {
		config.data.channel = 'web';
		uni.showLoading({
			title: '数据加载中',
			mask: false
		});
		return config
	},
	error => {
		uni.hideLoading();
		return Promise.reject(error)
	}
)

// 添加响应拦截器
instance.interceptors.response.use(
	response => {
		if (response.data.code !== 10200) {
			uni.showToast({
				title: response.data.msg,
				icon: 'none'
			})
		}
		uni.hideLoading();
		return response.data
	},
	error => {
		uni.hideLoading();
		uni.showToast({
			title: '网络异常，稍后再试',
			icon: 'none'
		})
		return Promise.reject(error)
	}
)

export default instance
